<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@taglib prefix="t" tagdir="/WEB-INF/tags"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta charset="utf-8">
<t:link />
<title>链接管理</title>
</head>

<body>

	<div class="manager">
		<div>链接管理</div>
		<button id="button" type="button" class="btn btn-default add">新增链接</button>
	</div>
	<div>
		<table class="table table-hover" id="cusTable" data-pagination="true"
			data-show-refresh="true" data-show-toggle="true"
			data-showColumns="true">
			<thead>
				<tr>
				    <td data-field="id" style="display: none"></td>
					<th data-field="title" class="tc">链接名称</th>
					<th data-field="url" class="tc">链接地址</th>
					<th data-field="memo" class="tc">链接描述</th>
					<th class="col-xs-2" data-field="action"
						data-formatter="actionFormatter" data-events="actionEvents">操作</th>
				</tr>
			</thead>
		</table>
	</div>


</body>


<script>
	$(document).ready(function() {
		//调用函数，初始化表格  
		initTable();
	});

	function initTable() {
		//先销毁表格  
		$('#cusTable').bootstrapTable('destroy');
		//初始化表格,动态从服务器加载数据  
		$("#cusTable").bootstrapTable({
			method : "POST", //使用get请求到服务器获取数据  
			url : "${pageContext.request.contextPath}/link/linkdata",//获取数据的Servlet地址  
			striped : true, //表格显示条纹  
			pagination : true, //启动分页  
			pageSize : 5, //每页显示的记录数  
			pageNumber : 1, //当前第几页  
			pageList : [ 5, 10, 15, 20, 25 ], //记录数可选列表  
			search : true, //是否启用查询  
			showColumns : true, //显示下拉框勾选要显示的列  
			showRefresh : true, //显示刷新按钮  
			sidePagination : "client", //表示客户端分页  
			onLoadSuccess : function(data) { //加载成功时执行  
				//alert("加载成功!" + data);
			},
			onLoadError : function(data) { //加载失败时执行  
				//alert("加载失败!" + data);
			}
		});
	}

	function actionFormatter(val, row, index) {
		return '<a class="mod tc" >修改</a> ' + '<a class="delete tc" >删除</a>';
	}

	window.actionEvents = {
		'click .mod' : function(e, value, row, index) {
			window.open("${pageContext.request.contextPath}/link/update?id="
					+ row.id, "_self");
		},
		'click .delete' : function(e, value, row, index) {
			if (row) {
				$.ajax({
					type : 'POST',
					url : '${pageContext.request.contextPath}/link/linkdelete',
					data : {
						id : row.id
					},
					success : function(data) {
						if (data) {
							alert("删除成功!");
							window.open(
									"${pageContext.request.contextPath}/link/index",
									"_self");
						}
					},
					error : function() {
						alert("删除失败!");
					}
				})
			}
		}
	}

	$("#button").click(
			function() {
				window.open("${pageContext.request.contextPath}/link/linkadd",
						"_self");
			})
</script>

</html>